package com.panda.mall.coupon.couponInfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.mall.common.mallCoupon.dto.CouponInfoDto;
import com.panda.mall.common.mallCoupon.entity.MallCouponInfo;
import com.panda.mall.common.result.Result;
import com.panda.mall.coupon.couponInfo.service.MallCouponInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: tcy
 * createDate: 2023/7/19
 * description: 优惠券信息
 */
@Api(tags = "优惠券信息")
@RestController
@RequestMapping("/coupon/info")
public class MallCouponInfoController {

    @Autowired
    MallCouponInfoService mallCouponInfoService;

    @ApiOperation(value = "条件分页查询", notes = "优惠券信息")
    @PostMapping("/pageList")
    public Result<Page<MallCouponInfo>> pageList(@RequestBody CouponInfoDto couponInfoDto){
        return Result.success(mallCouponInfoService.pageList(couponInfoDto));
    }

    @ApiOperation(value = "新增或修改", notes = "优惠券信息")
    @PostMapping("/saveOrUpdateCoupon")
    public Result<Boolean> saveOrUpdateCoupon(@RequestBody MallCouponInfo mallCouponInfo){
        return Result.success(mallCouponInfoService.saveOrUpdateCoupon(mallCouponInfo));
    }

    @ApiOperation(value = "优惠券详情", notes = "优惠券信息")
    @GetMapping("/details/{id}")
    public Result<MallCouponInfo> details(@PathVariable("id") Long id){
        return Result.success(mallCouponInfoService.details(id));
    }

    @ApiOperation(value = "删除优惠券", notes = "优惠券信息")
    @PostMapping("/delete")
    public Result<Boolean> delete(@RequestBody List<Long> ids){
        return Result.success(mallCouponInfoService.delete(ids));
    }
}
